package com.huika.renrench.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.huika.lib.ui.widget.dialog.MMAlert.DialogOnItemClickListener;
import com.huika.renrench.R;

public class MMAlertDialog {
	
	// begin---底部弹出宽，类似苹果的//////////////////////////////////////////
	public static Dialog createShowAlert(final Context context, int layoutId) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(layoutId, null);
		final int cFullFillWidth = 10000;
		layout.setMinimumWidth(cFullFillWidth);

		// set a large value put it in bottom
		final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet);
		Window w = dlg.getWindow();
		WindowManager.LayoutParams lp = w.getAttributes();
		lp.x = 0;
		final int cMakeBottom = -1000;
		lp.y = cMakeBottom;
		lp.gravity = Gravity.BOTTOM;// 改变显示位置
		dlg.onWindowAttributesChanged(lp);
		dlg.setCanceledOnTouchOutside(true);
		dlg.setContentView(layout);
		return dlg;
	}
	
	/**
	 * 系统更新提示对话框
	 * @param context
	 * @param contentResId
	 * @param leftClick
	 * @param rightClick
	 * @return
	 */
	public static Dialog createSoftwareUpdate(final Context context,String content, final View.OnClickListener leftClick, final View.OnClickListener rightClick) {
		final Dialog dlg = new Dialog(context, R.style.IsDelDialog);
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_exit, null); 
		TextView contentTv = (TextView) view.findViewById(R.id.tv_title_de);
		contentTv.setText(content);
		Button okBtn = (Button) view.findViewById(R.id.btn_affirm_de);
		Button cancel = (Button) view.findViewById(R.id.btn_cancel_de);
		// 确定实名认证
		okBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dlg.dismiss();
				if (null != rightClick) {
					rightClick.onClick(v);
				}
			}
		});
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dlg.dismiss();
				if (leftClick != null) leftClick.onClick(v);
			}
		});
		dlg.setCanceledOnTouchOutside(true);
		dlg.setContentView(view);
		return dlg;
	}
	public static Dialog ClearcacheDate(final Context context,String content, final View.OnClickListener leftClick, final View.OnClickListener rightClick) {
		final Dialog dlg = new Dialog(context, R.style.IsDelDialog);
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_clearcache, null); 
		TextView contentTv = (TextView) view.findViewById(R.id.tv_title_de);
		contentTv.setText(content);
		Button okBtn = (Button) view.findViewById(R.id.btn_affirm_de);
		Button cancel = (Button) view.findViewById(R.id.btn_cancel_de);
		// 确定实名认证
		okBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dlg.dismiss();
				if (null != rightClick) {
					rightClick.onClick(v);
				}
			}
		});
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dlg.dismiss();
				if (leftClick != null) leftClick.onClick(v);
			}
		});
		dlg.setCanceledOnTouchOutside(true);
		dlg.setContentView(view);
		return dlg;
	}
	
	/**拨打电话*/
	public static Dialog createPrivateDialogExitDialog(final Context context, int fCStrId, int sCStrId, final DialogOnItemClickListener onItemClickListener) {
		final Dialog dlg = createShowAlert(context, R.layout.alert_notitle_tel);
		dlg.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dlg.dismiss();
			}
		});
		TextView item_first = (TextView) dlg.findViewById(R.id.item_first);
		item_first.setText(fCStrId);
		TextView item_second = (TextView) dlg.findViewById(R.id.item_second);
		item_second.setText(sCStrId);
		item_second.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dlg.dismiss();
				if (onItemClickListener != null)
					onItemClickListener.onItemClickListener(v, 0);
			}
		});
		return dlg;
	}
	
}
